import Vue from 'vue'
import { $POST, $DELETE, $PUT, $GET } from '__UTILS__/http_request/request-method.js'
import VueConfig, {preffix} from '__CONFIG__/vue-config.js'
const disposeResFunName = VueConfig[preffix + 'REQUEST_DISPOSE'].name //获取到处理返回结果函数名
const disposeResFun = Vue.prototype[disposeResFunName] // 获取到了处理函数

//注册用户
export function createUser({
  nickname, password, code, email
}) {
  const API = 'users'
  return $POST(API, { nickname, password, code, email })
}

//验证用户登入
export function vertifyUser({
  vertify, code, password
}) {
  const API = 'users/vertify'
  return $POST(API, { vertify, password, code })
}

//通过验证码找回密码
export function findPassword({
  vertify, code, newPassword, oldPassword, access_token
}) {
  const API = 'users/' + vertify + '/password' 
  return $PUT(API, { newPassword, code, oldPassword, access_token })
}

//获取列表
export function index() {
  const API = 'users'
  return $GET(API, disposeResFun)
}

//获取单个
export function show({id, access_token}) {
  const API = 'users' + '/' + id
  return $GET(API, {access_token}, disposeResFun)
}

//获取个人的基本信息，组成信息面板
export function getBaseInfo(vertify) {
  const API = 'users' + '/' + vertify + '/base_info'
  return $GET(API, disposeResFun)
}

//更新
export function update(id, {access_token, UPDATE}) {
  const API = 'users' + '/' + id
  return $PUT(API, {access_token, UPDATE}, disposeResFun)
}

//获取用户所有文章
export function getArticlesByUserId(id) {
  const API = 'users' + '/' + id + '/articles'
  return $GET(API, disposeResFun)
}

//获取用户所有消息
export function getSystemMessage(id) {
  const API = 'users' + '/' + id + '/system_messages'
  return $GET(API, disposeResFun)
}

//获取用户所有收藏
export function getCollections(id) {
  const API = 'users' + '/' + id + '/collections'
  return $GET(API, disposeResFun)
}